//  封装接口
import http from "./axios"
//定义方法  统一管理请求

//注册
function  enrollList(loginName,code,phonenumber,password,userName,sex,remark){
    let  urlParams = new URLSearchParams()
    urlParams.append("loginName",loginName)
    urlParams.append("code",code)
    urlParams.append("phonenumber",phonenumber)
    urlParams.append("password",password)
    urlParams.append("userName",userName)
    urlParams.append("sex",sex)
    urlParams.append("remark",remark)


    return http.post("/news-api/api/registry",urlParams)

    // return http.post("/course-api/api/registry",urlParams)

}
export {enrollList}


//登录

// function login(username,password,isrememberMe) {
//     let urlParams = new URLSearchParams()
//     urlParams.append("username",username)
//     urlParams.append("password",password)
//     urlParams.append("isrememberMe",isrememberMe)

function login(username,password,isRemberMe) {
    let urlParams = new URLSearchParams()
    urlParams.append("username",username)
    urlParams.append("password",password)
    urlParams.append("rememberMe",isRemberMe)


    return http.post("/news-api/api/login",urlParams)
}
export {login}

//短信验证码

// export function sms(mobile){
//    return http.get(`/news-api/api/short-message/vcode/${mobile}`)

export function Sms(mobile){
    return http.get("/news-api/api/short-message/vcode/"+mobile)

}

//查看个人信息
export function getUserInfo() {
    return http.get("/news-api/api/login-user/info")
}

//忘记密码
function pwdList(loginName,password,phonenumber,code){
    let urlParams = new URLSearchParams()
    urlParams.append("loginName",loginName)
    urlParams.append("password",password)
    urlParams.append("phonenumber",phonenumber)
    urlParams.append("code",code)

    return http.post("/news-api/api/password/forget",urlParams)

}
export {pwdList}

//修改头像
function avatarList(avatarfile){
    let urlParams = new FormData()
    urlParams.append("avatarfile",avatarfile)

    return http.post("/news-api/api/system/user/profile/update/avatar/nos",urlParams)

    // return http.post("/course-api/api/system/user/profile/update/avatar/nos",urlParams)

}
export {avatarList}

//上传图片
function imgList(file,fileUseForEnum){
    let urlParams = new URLSearchParams()
    urlParams.append("file",file)
    urlParams.append("file",fileUseForEnum)

    return http.post("/news-api/api/nos/upload/image",urlParams)
}
export {imgList}

//点赞
export function praiseList(articleId){
    return http.get("/news-api/api/cms/article/add/zan/"+articleId)
}


//修改个人信息
function setUserInfo(type,payload){
    let urlParams = new URLSearchParams()
    urlParams.append(type,payload)
  /*  urlParams.append("userName",email)
    urlParams.append("userName",phonenumber)
    urlParams.append("userName",sex)

    urlParams.append("remark",remark)

    return http.post("/news-api/api/system/user/profile/update",urlParams)

    urlParams.append("remark",remark)*/
    return http.post("/news-api/api/system/user/profile/update",urlParams)

}
export {setUserInfo}

// 退出登陆
export function ExitLogin() {
    return http.get("/news-api/api/logout")
}
//点赞
// export function praiseList(articleId){
//     return http.get(`/news-api/api/cms/article/add/zan/${articleId}`)
// }
//增加阅读量
export function readList(id){
    return http.get(`/news-api/api/cms/article/open/add/read-num/${id}`)
}
//获取新闻详情
export function newsdetail(articleId){
    return http.get(`/news-api/api/cms/article/open/detail/${articleId}`)
}
//新闻订阅
function getsubscribe(categoryIds){
    let urlParams = new URLSearchParams()
    urlParams.append("categoryIds",categoryIds)
    return http.post(`/news-api/api/cms/userCategory/subscription/category`,urlParams)
}
export {getsubscribe}
//订阅列表
export function getsubscribeList(){
    return http.get(`/news-api/api/cms/category/subscription/list`)
}
//收藏文章(可以取消)
export function collectiontext(articleId){
    return http.get(`/news-api/api/cms/collect/collect/article/${articleId}`)
}
//收藏文章列表
export function collectiontextlist(){
    return http.get(`/news-api/api/cms/article/collect/list`)
}
//评论列表
function commentsList(postsId,pageNum,pageSize){
    let urlParams = new URLSearchParams()
    urlParams.append("postsId",postsId)
    urlParams.append("pageNum",pageNum)
    urlParams.append("pageSize",pageSize)
    return http.post("/news-api/api/bbs/bbsComment/open/list",urlParams)
}

export {commentsList}

//轮播图
export  function swiper(pageNum,pageSize){
    let url = new URLSearchParams()
    url.append('pageNum',pageNum)
    url.append('pageSize',pageSize)

    return http.post('/news-api/api/cms/article/open/banner/list',url)

}
//热门新闻
export  function switchOne(pageNum,pageSize) {
    let url = new URLSearchParams()

    // url.append('pageNum', pageNum)
    // url.append('pageSize', pageSize)

    // return http.post('/news-api/api/cms/article/open/hot/list', url)

    url.append('pageNum',pageNum)
    url.append('pageSize',pageSize)
    return http.post(`/news-api/api/cms/article/open/hot/list?pageNum=${pageNum}&pageSize=${pageSize}`)

}

//新闻列表
export function news(pageNum,pageSize,categoryId){
    let url = new URLSearchParams()
    url.append('pageNum',pageNum)
    url.append('pageSize',pageSize)
    url.append('categoryId',categoryId)
    return http.post(`/news-api/api/cms/article/open/list?pageNum=${pageNum}&pageSize=${pageSize}&categoryId=${categoryId}`)
}
//tab切换
export  function  newList(pageNum,pageSize){
    let url = new URLSearchParams()
    url.append('pageNum',pageNum)
    url.append('pageSize',pageSize)

    return http.post('/news-api/api/cms/category/open/list',url)

    // return http.get("/news-api/api/logout")
}

export function joke(){
    return http.get('https://www.mxnzp.com/api/jokes/list/random?app_id=mpquhklltntoerkn&app_secret=Y3h1SmpIeWtvMU55cU04QTNDalAyZz09')
}
export function epidemic(city){
    return http.get(`https://www.mxnzp.com/api/weather/current/${city}?app_id=upxovtftszqknbss&app_secret=K3RPUlBwQmZaOTdqVWhaWjQ5eFdEQT09`)
}
export function covid(){
    return http.get('/covid-api/g2/getOnsInfo?name=disease_h5')
    // return http.get('https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5')
}

